package com.jic.member.impl;

import com.google.common.collect.Lists;
import com.jic.member.entity.MemDiscountCardEntity;
import com.jic.member.entity.MemDiscountCardPeriodEntity;
import com.jic.member.mapper.*;
import com.jic.member.service.GenerateCardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * 折扣卡
 * @since : 2020-07-02
 * @author MJ
 */
@Service
@Slf4j
public class GenerateCardServiceImpl implements GenerateCardService {
    //线程池

    private static Integer PARTITION_NUM = 10000;

    @Autowired
    MemDiscountCardEntityMapper memDiscountCardEntityMapper;

    @Autowired
    MemDiscountCardPeriodEntityMapper memDiscountCardPeriodEntityMapper;



    @Transactional(rollbackFor = Exception.class)
    @Override
    public void processGennerCode(List<MemDiscountCardEntity> list, MemDiscountCardPeriodEntity memDiscountCardPeriodEntity){
        List<List<MemDiscountCardEntity>> partitions = Lists.partition(list, PARTITION_NUM);
        for (List<MemDiscountCardEntity> partition : partitions) {
            memDiscountCardEntityMapper.foreachInsert(partition);
        }
    }
}
